<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>装货地址管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			//获取第二级数据
			$("#provinceId").change(function(){
				var $provinceId = $("#provinceId").val();
				$("#cityId").empty();
				if($provinceId != null && typeof($provinceId) !="undefined" && $provinceId != ''){
					$.ajax({
						url:"${ctx}/tb_areas/tbAreas/findCityByParentId",
						type:"post",
						data:{"parentId":$provinceId},
						dataType:"json",
						success:function(data){
							$.each(data, function(index,item){
		                    	$("#cityId").append("<option class='required' value='"+item.id+"'>"+item.areaname+"</option>")
			                }); 
						}
					});
					$("#cityId").removeClass("hide");
				}else{
					alert("请选择城市");
					$("#cityId").addClass("hide");
					$("#areaId").addClass("hide")
				}
			});
		});
		
		function findcity(t,o){
			var $cityId = $("#cityId").val();
				$("#areaId").empty();
				if($cityId != null && typeof($cityId) !="undefined" && $cityId != ''){
					$.ajax({
						url:"${ctx}/tb_areas/tbAreas/findCityByParentId",
						type:"post",
						data:{"parentId":$cityId},
						dataType:"json",
						success:function(data){
							$.each(data, function(index,item){
		                    	$("#areaId").append("<option class='required' value='"+item.id+"'>"+item.areaname+"</option>")
			                }); 
						}
					});
					$("#areaId").removeClass("hide");
				}else{
					alert("请选择城市");
					$("#areaId").addClass("hide")
				} 
		
		}
		
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/tb_loading_address/tbLoadingAddress/">装货地址列表</a></li>
		<li class="active"><a href="${ctx}/tb_loading_address/tbLoadingAddress/form?id=${tbLoadingAddress.id}">装货地址<shiro:hasPermission name="tb_loading_address:tbLoadingAddress:edit">${not empty tbLoadingAddress.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="tb_loading_address:tbLoadingAddress:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tbLoadingAddress" action="${ctx}/tb_loading_address/tbLoadingAddress/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">简称：</label>
			<div class="controls">
				<form:input path="shortName" htmlEscape="false" maxlength="25" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系人：</label>
			<div class="controls">
				<form:input path="persion" htmlEscape="false" maxlength="15" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系电话：</label>
			<div class="controls">
				<form:input path="tell" htmlEscape="false" maxlength="11" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">地址：</label>
			<div class="controls">
			<form:select id="provinceId" path="provinceId" class="input-small">
				<form:option value="" label=""/>
				<form:options items="${tbAreas}" itemValue="id" itemLabel="areaname" htmlEscape="false"/>
			</form:select>
			<%--市 --%>
			<form:select id="cityId" path="cityId" class="input-small" onchange="findcity(this,obj)"></form:select>
			<%--区 --%>
			<form:select id="areaId" path="areaId" class="input-small"></form:select>
				<form:input path="address" htmlEscape="false" maxlength="20" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">市：</label>
			<div class="controls">
				<form:input path="cityId" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">区：</label>
			<div class="controls">
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<%-- <div class="control-group">
			<label class="control-label">详细地址：</label>
			<div class="controls">
				<form:input path="address" htmlEscape="false" maxlength="155" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="tb_loading_address:tbLoadingAddress:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>